<?php
require_once dirname ( __FILE__ ) . '/../../bootstrap/unit.php';

class unit_OrganizationalUnitTest extends WildlivePHPUnitTestCase {
  
  private function loadFixtureSet001() {
    $this->loadFixtures ( 'organizational_unit.yml','organizational_entity.yml', 'organizational_property_type.yml', 'organizational_property.yml', 'organizational_entity_property_assignment.yml', 'organizational_unit_property_assignment.yml' );
  }
  
  /**
   * @return OrganizationalUnit
   */
  private function getRedChapter() {
    return OrganizationalUnitTable::getInstance()->findOneByName('Stamm Rot');
  }
  
  /**
   * @return OrganizationalUnit
   */
  private function getBlueChapter() {
    return OrganizationalUnitTable::getInstance()->findOneByName('Stamm Blau');
  }
  
  public function testGetPropertyValueShouldPreferUnitPropertiesOverEntityProperties() {
    $this->loadFixtureSet001();
    
    // Chapter with can_have_members := 0
    $chapter = $this->getBlueChapter();
    $this->assertEquals(0, $chapter->getPropertyValue('can_have_members'));
    
    // Chapter with can_have_members := 1
    $chapter = $this->getRedChapter();
    $this->assertEquals(1, $chapter->getPropertyValue('can_have_members'));
  }
  
  public function testGetPropertyValueShouldReturnNullForInvalidProperty() {
    $this->loadFixtureSet001();
    
    $chapter = $this->getBlueChapter();
    $this->assertNull($chapter->getPropertyValue('some_random_invalid_property'));
  }
  
  public function testGetPropertyValuesShouldReturnArrayOfAllOrganizationalPropertyAssignmentAggregationInstances() {
    $this->loadFixtureSet001();
    
    $chapter = $this->getBlueChapter();
    $properties = $chapter->getPropertyValues();
    $this->assertTrue(is_array($properties));
  }
}